import java.util.Scanner;

public class test6 {
    public static void main(String[] args) {


    String corretnum="8799";
    int maxattempts=3;
    int attempts=0;
    Scanner scanner =new Scanner(System.in);
    while(attempts<maxattempts){
        System.out.println("请输入密码：");
        String inputnum=scanner.nextLine();

        if (inputnum.equals(corretnum)){
            System.out.println("登录成功");
            break;

        }else {
            attempts++;
            System.out.println("密码错误，你还有"+(maxattempts-attempts)+"次机会");
            if (attempts==maxattempts-1){
                System.out.println("这是最后一次机会。");
            }
        }

    }
    if (attempts==maxattempts){
        System.out.println("退出程序");
    }
    scanner.close();
}
}
